Skip to content

sql: fix FETCH FIRST on empty WITH HOLD cursor#171337

Merged
rail merged 1 commit into
cockroachdb:masterfrom
virajchogle:cursor-fetch-first-empty-171238
Jun 10, 2026
Merged

sql: fix FETCH FIRST on empty WITH HOLD cursor#171337
rail merged 1 commit into
cockroachdb:masterfrom
virajchogle:cursor-fetch-first-empty-171238

Conversation

@virajchogle

Copy link
Copy Markdown
Contributor

Fixes #171238

FETCH FIRST on a persisted WITH HOLD cursor over an empty result set returned an internal error (decoding unset EncDatum) instead of zero rows. In fetchMoveNodeBase.nextInternal, the FetchFirst branch for curRow == 0 discarded the bool returned by sqlCursor.Next and unconditionally reported a row, so the caller tried to decode an unset EncDatum.

This propagates Next's (more, err) directly from the case 0 branch, matching the FetchAbsolute path just below.

Related to #145362 / #145391 (prior fix for FETCH ABSOLUTE), but the asymmetric FetchFirst path was not reached by that change.

Epic: none

Release note (bug fix): FETCH FIRST on an empty WITH HOLD cursor no longer returns an internal error.

FETCH FIRST on an empty persisted WITH HOLD cursor discarded the
"no more rows" signal from sqlCursor.Next and returned true, causing
the caller to decode an unset EncDatum. Propagate Next's (more, err)
directly, matching the FetchAbsolute path.

Fixes cockroachdb#171238

Release note (bug fix): FETCH FIRST on an empty WITH HOLD cursor no
longer returns an internal error.
@trunk-io

trunk-io Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

😎 Merged manually by @rail - details.

@blathers-crl

blathers-crl Bot commented Jun 2, 2026

Copy link
Copy Markdown

Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR.

My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI.

I have added a few people who may be able to assist in reviewing:

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@blathers-crl blathers-crl Bot added O-community Originated from the community X-blathers-triaged blathers was able to find an owner labels Jun 2, 2026
@blathers-crl blathers-crl Bot requested a review from yuzefovich June 2, 2026 03:54
@cockroach-teamcity

Copy link
Copy Markdown
Member

This change is Reviewable

@trunk-io

trunk-io Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

invalid

An error occurred while handling your Trunk command: Unexpected argument 'when'. This command does not take positional arguments

@virajchogle

Copy link
Copy Markdown
Contributor Author

@yuzefovich friendly bump. This has been open about a week with CI green. Whenever you have a moment, would appreciate a look. Happy to address any feedback.

@yuzefovich yuzefovich requested review from a team and DrewKimball and removed request for yuzefovich June 8, 2026 23:58

@DrewKimball DrewKimball left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: Nice work, thanks for the fix!

@DrewKimball reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on virajchogle).

@DrewKimball

Copy link
Copy Markdown
Collaborator

/trunk merge

@rail rail merged commit 405e0d2 into cockroachdb:master Jun 10, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-community Originated from the community target-release-26.3.0 X-blathers-triaged blathers was able to find an owner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sql: FETCH FIRST FROM WITH HOLD cursor triggers internal error (decoding unset EncDatum)

4 participants